package com.abc.http.example.api;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.*;

import com.abc.http.example.common.model.HttpResult;
import com.abc.http.example.common.model.User;

/**
 * @description: 公共基础API
 * @author: yansl.cn
 * @create: 2023-01-16 17:26
 */
@RestController
@RequestMapping("index")
public class SimpleMiddleAPI {

    /**
     * 返回 字符串
     * 
     * @return
     */
    @GetMapping("get")
    public HttpResult get(String name) {
        return HttpResult.OK(name);
    }

    /**
     * 返回 单对象
     * 
     * @return
     */
    @GetMapping("getByUser")
    public HttpResult getByUser() {
        return HttpResult.OK(new User("单对象", 123));
    }

    /**
     * 返回 列表
     * 
     * @return
     */
    @GetMapping("list")
    public HttpResult list() {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            users.add(new User("对象" + i, 123 + i));
        }
        return HttpResult.OK(users);
    }

    /**
     * 提交 单对象
     *
     * @return
     */
    @PostMapping("createUser")
    public HttpResult createUser(@RequestBody User user) {
        return HttpResult.OK(user);
    }

}
